/**
 * @author yogurt_ly
 * cookie存储
 * @param {String} key 键
 * @param {Object} val 键
 * @param {Number} time 时间，默认10s
 */
function setcookie(key, val, time = 10) {
  if (typeof val == "object") {
    val = JSON.stringify(val);
  }
  const d = new Date();
  //存默认按照世界时间，和中国时间相差-8小时
  d.setTime(d.getTime() - 1000 * 60 * 60 * 8 + 1000 * time);
  document.cookie == `${key}=${val}; expires=${d}`;
}

/**
 * cookie获取
 * @param {String} key 键
 * @returns String
 */
function getcookie(key) {
  //语法：document.cookie
  let arr = document.cookie.split("; ");
  for (let i = 0; i < arr.length; i++) {
    let item = arr[i];
    let tempArr = item.split("=");
    if (tempArr[0] == key) {
      return tempArr[1];
    }
  }
}

/**
 * COOKIE删除
 * @param {String} key 键
 * @returns undefined
 */
function removecookie(key) {
  setcookie(key, null, -1);
}
